From: Paul Durrant Date: Wed, 25 Nov 2015 14:51:00 +0000 (+0000) Subject: libxl: implement libxl__xs_mknod using XS_WRITE rather than XS_MKDIR X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~2151 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22man:///%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22man:/?a=commitdiff_plain;h=53c3d93af03d13e7e2931a352211da4824bd44ed;p=xen.git libxl: implement libxl__xs_mknod using XS_WRITE rather than XS_MKDIR This patch modifies the implentation of libxl__xs_mknod() to use XS_WRITE rather than XS_MKDIR since passing an empty value to the former will ensure that the path is both existent and empty upon return, rather than merely existent. The function return type is also changed to a libxl error value rather than a boolean, it's declaration is accordingly moved into the 'checked' section in libxl_internal.h, and a comment is added to clarify its semantics. This patch also contains as small whitespace fix in the definition of libxl__xs_mknod() and the addition of 'ok' to CODING_STYLE as the canonical variable name for holding return values from boolean functions. Signed-off-by: Paul Durrant Cc: Ian Jackson Cc: Stefano Stabellini Cc: Ian Campbell Cc: Wei Liu Acked-by: Ian Jackson --- diff --git a/tools/libxl/CODING_STYLE b/tools/libxl/CODING_STYLE index 919bcc636c..522d1c98b4 100644 --- a/tools/libxl/CODING_STYLE +++ b/tools/libxl/CODING_STYLE @@ -35,6 +35,7 @@ The following local variable names should be used where applicable: int rc; /* a libxl error code - and not anything else */ int r; /* the return value from a system call (or libxc call) */ + bool ok; /* the success return value from a boolean function */ uint32_t domid; libxl__gc *gc; diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index a671a61665..d2bda0af0a 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -680,10 +680,6 @@ _hidden char *libxl__xs_read(libxl__gc *gc, xs_transaction_t t, _hidden char **libxl__xs_directory(libxl__gc *gc, xs_transaction_t t, const char *path, unsigned int *nb); /* On error: returns NULL, sets errno (no logging) */ -_hidden bool libxl__xs_mknod(libxl__gc *gc, xs_transaction_t t, - const char *path, struct xs_permissions *perms, - unsigned int num_perms); - _hidden char *libxl__xs_libxl_path(libxl__gc *gc, uint32_t domid); @@ -692,6 +688,11 @@ _hidden char *libxl__xs_libxl_path(libxl__gc *gc, uint32_t domid); * fails it logs and returns ERROR_FAIL. */ +/* On success, path will exist and will have an empty value */ +int libxl__xs_mknod(libxl__gc *gc, xs_transaction_t t, + const char *path, struct xs_permissions *perms, + unsigned int num_perms); + /* On success, *result_out came from the gc. * On error, *result_out is undefined. * ENOENT counts as success but sets *result_out=0 diff --git a/tools/libxl/libxl_xshelp.c b/tools/libxl/libxl_xshelp.c index cb6a559f3c..8554ee54df 100644 --- a/tools/libxl/libxl_xshelp.c +++ b/tools/libxl/libxl_xshelp.c @@ -147,14 +147,26 @@ char **libxl__xs_directory(libxl__gc *gc, xs_transaction_t t, return ret; } -bool libxl__xs_mknod(libxl__gc *gc, xs_transaction_t t, - const char *path, struct xs_permissions *perms, - unsigned int num_perms) +int libxl__xs_mknod(libxl__gc *gc, xs_transaction_t t, + const char *path, struct xs_permissions *perms, + unsigned int num_perms) { libxl_ctx *ctx = libxl__gc_owner(gc); - if (!xs_mkdir(ctx->xsh, t, path)) - return false; - return xs_set_permissions(ctx->xsh, t, path, perms, num_perms); + bool ok; + + ok = xs_write(ctx->xsh, t, path, "", 0); + if (!ok) { + LOGE(ERROR, "xenstore write failed: `%s' = ''", path); + return ERROR_FAIL; + } + + ok = xs_set_permissions(ctx->xsh, t, path, perms, num_perms); + if (!ok) { + LOGE(ERROR, "xenstore set permissions failed on `%s'", path); + return ERROR_FAIL; + } + + return 0; } char *libxl__xs_libxl_path(libxl__gc *gc, uint32_t domid)